<%@ page contentType="text/html;charset=UTF-8" %>
<%@include file="../../common/sessionValidate.jsp" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
<head>
    <title>T_contract信息维护</title>
    <%@ include file="../../common/meta.jsp" %>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen" id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
</head>
<style>
    hr {
        margin-top: 1px;
        border-bottom: 1px solid #1BBC9B;
    }
</style>
<body>
<form class="form-horizontal form-bordered form-row-strippe" name="ffAdd" id="ffAdd" mentod="post" role="form"
      data-toggle="validator" enctype="multipart/form-data">
    <div class="" style="margin-right:2px;padding-right:1px;">

        <!-------------------------- 面板  start--------------------------------->
        <div class="panel panel-primary">
            <div class="panel-heading clearfix" id="addHeaderDiv">
            </div>
            <div class="panel-body">
                <div class="row">
                    <h5>&nbsp;&nbsp;合同信息</h5>
                    <hr>
                    <div class="col-xs-6"><!--start 换列-->
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 合同号</label>
                                <div class="col-xs-9">
                                    <input id="contractno" name="contractno" type="text" class="form-control"
                                           placeholder="contractno"/>
                                    <input id="contractid" name="contractid" type="hidden"/>
                                    <input id="contracttype" name="contracttype" type="hidden" value="销售"/>
                                    <input id="billrowsnum" name="billrowsnum" type="hidden" value=""/>

                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 销售类型</label>
                                <div class="col-xs-9">
                                    <select id="ext1" name="ext1" type="text" class="form-control">
                                        <option value="整栋">整栋</option>
                                        <option value="房源">房源</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 楼栋</label>
                                <div class="col-xs-9">
                                    <select id="buildingname" name="buildingname" type="text" class="form-control">
                                        <option value="C">C</option>
                                        <option value="D">D</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <!--如果输入元素是奇数个元素，在n=size/2?int时输出2列格式；如果元素是奇数个，需要在n=size/2?int+1时输出2列格式；需要换列，每行最多显示2列-->
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 园区对接人</label>
                                <div class="col-xs-9">
                                    <input id="linkman" name="linkman" type="text" class="form-control"
                                           placeholder="linkman"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 房源</label>
                                <div class="col-xs-9">
                                    <select id="housename" name="housename" type="text" class="form-control">
                                        <option value="501">501</option>
                                        <option value="502">501</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div><!--end 换列-->
                </div><!--end row-->
            </div><!--end body-->
        </div>
        <!--------------------------面板 end------------------------------------>

        <!-------------------------- 业主租客 面板  start--------------------------------->
        <div class="panel panel-primary">
            <div class="panel-body">
                <div class="row">
                    <h5>&nbsp;&nbsp;业主/租客信息</h5>
                    <hr>
                    <div class="col-xs-6"><!--start 换列-->
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 业主/租客</label>
                                <div class="col-xs-9">
                                    <input id="conpanyname" name="conpanyname" type="text" class="form-control"
                                           placeholder="contractid"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 签订人</label>
                                <div class="col-xs-9">
                                    <input id="signer" name="signer" type="text" class="form-control"
                                           placeholder="contractno"/>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <!--如果输入元素是奇数个元素，在n=size/2?int时输出2列格式；如果元素是奇数个，需要在n=size/2?int+1时输出2列格式；需要换列，每行最多显示2列-->
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 附件</label>
                                <div class="col-xs-9">
                                    <input id="attachpath" name="attachpath" type="text" class="form-control"
                                           placeholder="status"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 联系人</label>
                                <div class="col-xs-9">
                                    <input id="linkman" name="linkman" type="text" class="form-control"
                                           placeholder="linkman"/>
                                </div>
                            </div>
                        </div>
                    </div><!--end 换列-->
                </div><!--end row-->
            </div><!--end body-->
        </div>
        <!--------------------------业主租客 面板 end------------------------------------>

        <!-------------------------- 费用信息 面板  start--------------------------------->
        <div class="panel panel-primary">
            <div class="panel-body">
                <div class="row">
                    <h5>&nbsp;&nbsp;费用条款</h5>
                    <hr>
                    <div class="col-xs-6"><!--start 换列-->
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 销售面积（平方米）</label>
                                <div class="col-xs-9">
                                    <input id="area" name="area" type="text" class="form-control"
                                           placeholder="contractid"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 销售单价</label>
                                <div class="col-xs-9">
                                    <input id="price" name="price" type="text" class="form-control"
                                           placeholder="contractno"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 付款方式</label>
                                <div class="col-xs-9">
                                    <select id="paytype" name="paytype" type="text" class="form-control">
                                        <option value="1">一次性付款</option>
                                        <option value="2">分期付款</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <!--如果输入元素是奇数个元素，在n=size/2?int时输出2列格式；如果元素是奇数个，需要在n=size/2?int+1时输出2列格式；需要换列，每行最多显示2列-->
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 签订时间</label>
                                <div class="col-xs-9">
                                    <input id="signtime" name="signtime" type="text" class="form-control"
                                           placeholder="status"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 合同总价</label>
                                <div class="col-xs-9">
                                    <input id="totalprice" name="totalprice" type="text" class="form-control"
                                           placeholder="linkman"/>
                                </div>
                            </div>
                        </div>
                        <div class="col-xs-12">
                            <div class="form-group">
                                <label class="control-label col-xs-3"> 付款时间</label>
                                <div class="col-xs-9">
                                    <input id="paytime" name="paytime" type="text" class="form-control"
                                           placeholder="linkman"/>
                                </div>
                            </div>
                        </div>
                    </div><!--end 换列-->
                </div><!--end row-->
            </div><!--end body-->

            <!--------------------------信息列表：带表格面板  start--------------------------------->
            <div class="panel panel-primary">
                <div class="panel-heading clearfix">
                    <i class='icon-reorder'></i>&nbsp; 合同额明细列表
                    <span class="text-right pull-right ">
                        <button type="button" class=" btn btn-success btn-xs img-rounded" id="creatButton" onclick="creatBill()">生成合同额明细</button>
                        <button type="button" class=" btn btn-success btn-xs img-rounded" id="creatButton2" onclick="creatBill()">手工添加</button> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    </span>
                </div>
                <div class="panel-body">
                    <table id="grid" class="table table-condensed table-striped table-bordered table-hover"
                           class="sortable" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
                        <thead id="grid_head">
                        <tr>
                            <th onclick="sortTableT.sort('grid',0,'String')"> 开始时间</th>
                            <th onclick="sortTableT.sort('grid',0,'String')"> 结束时间</th>
                            <th onclick="sortTableT.sort('grid',0,'String')"> 面积</th>
                            <th onclick="sortTableT.sort('grid',0,'String')"> 付款日</th>
                            <th onclick="sortTableT.sort('grid',0,'String')"> 最终金额</th>
                            <!--<th style="width:150px">操作</th> -->
                        </tr>
                        </thead>
                        <tbody id="grid_body"></tbody>
                    </table>
                </div>
            </div>
            <!--------------------------信息列表：带表格面板 end------------------------------------>


            <div class="modal-footer bg-info " id='buttonDiv'>
            </div>
        </div>
        <!--------------------------费用信息 面板 end------------------------------------>


        <!-- 模态框（Modal）start -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
             aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">提示</h4>
                    </div>
                    <div class="modal-body" id="myModalMessDiv"></div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
        <!-- 模态框（Modal）end -->
    </div>
</form>
</body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script src="<%=basePath%>js/jquery-1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js"></script>
<script src="<%= basePath %>js/calendar.js"></script>
<script type="text/javascript">
    var insertrowsnum = 0; //全局插入行的数字；每生成一行加1；

    //新增保存数据
    function add() {
        $("#addSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_contract/saveT_contract?time=" + Math.random();
        var postData = $("#ffAdd").serializeArray();
        //alert(postData);
        $.post(url, postData, function (data) {
            //var data = $.parseJSON(data);
            if (data.result == "success") {
                //保存成功  1.关闭弹出层，
                showSuccessTips("恭喜保存成功!", "提示");
                history.goBack();
            } else {
                $("#addSaveButton").removeAttr("disabled");
                //showErrorTips("保存数据失败!", "错误信息：");
                $("#myModal").modal('show'); //hide;
                $("#myModalMessDiv").html("<font color='red'>对不起,保存数据失败，失败原因：" + data.info + "</font>");
                return false;
            }
        }).error(function () {
            $("#addSaveButton").removeAttr("disabled");
            //showErrorTips("保存数据失败!", "错误信息：");
            $("#myModal").modal('show'); //hide;
            $("#myModalMessDiv").html("<font color='red'>对不起,保存数据失败，失败原因：" + data.info + "</font>");
        });
    }

    //更新修改数据到后台
    function edit() {
        $("#editSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_contract/updateT_contract?time=" + Math.random();
        myEdit2(url);
    }

    //更新修改数据到后台
    function creatBill() {
        insertrowsnum = insertrowsnum+1; //全局变量加1；
        $("#billrowsnum").val(insertrowsnum);
        alert("billrowsnum="+$("#billrowsnum").val());
        var billstartdate = "billstartdate"+ insertrowsnum;
        var billenddate = "billenddate"+ insertrowsnum;
        var billarea = "billarea"+ insertrowsnum;
        var billpaydate = "billpaydate"+ insertrowsnum;
        var billfinalmone = "billfinalmone"+ insertrowsnum;

        var str = "<tr>";
        str += "<td><input id='"+billstartdate+"' name='"+billstartdate+"' type='text' class='form-control' /></td>";
        str += "<td><input id='"+billenddate+"' name='"+billenddate+"' type='text' class='form-control' /></td>";
        str += "<td><input id='"+billarea+"' name='"+billarea+"' type='text' class='form-control' /></td>";
        str += "<td><input id='"+billpaydate+"' name='"+billpaydate+"' type='text' class='form-control' /></td>";
        str += "<td><input id='"+billfinalmone+"' name='"+billfinalmone+"' type='text' class='form-control' /></td>";
        str += "</tr>";
        $("#grid_body").append(str);
    }

    //更新修改数据到后台并且启动工作流
    function tjsh() {
        $("#editSaveButton").attr("disabled", true);
        $("#tjshSaveButton").attr("disabled", true);
        var url = "<%=basePath%>t_contract/tjshT_contract?time=" + Math.random();
        myCurdTjsh(url);
    }

    //初始化页面及校验
    $().ready(function () {
        //1、初始化数据显示
        var name = "合同";
        var optype = '<%=request.getParameter("oplx")%>';
        var id = '<%=request.getParameter("id")%>';
        //alert("optype="+optype+";id="+id);
        if (optype == 'add') {
            $("#ffAdd")[0].reset();/*重置表单*/
            var basePath = "<i class='icon-plus'></i>&nbsp;";
            setHeader2("新增" + name, basePath);//设置addHeaderDiv标题文字及按钮
            setButtonDivAdd2();//设置adddiv的 操作按钮
        } else if (optype == 'edit') {
            var basePath = "<i class='icon-pencil'></i>&nbsp;";
            setHeader2("修改" + name, basePath);//设置addHeaderDiv标题文字及按钮
            //setButtonDivEdit2();//设置adddiv的 操作按钮
            setButtonDivEdit4();//设置adddiv的 操作按钮
            var url = "<%=basePath%>t_contract/getT_contract?id=" + id + "&time=" + Math.random();
            $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
                setValue(data);
                //alert($("#effect_date").val()+""+jsonDateFormat($("#effect_date").val()));
                //$("#effect_date").val(jsonDateFormat($("#effect_date").val())); //重新设置日期类型的值
            });
        } else if (optype == 'view') {
            var basePath = "<i class='icon-eye-open'></i>&nbsp;";//设置addHeaderDiv标题文字及按钮
            setHeader2("查看" + name, basePath);
            setButtonDivView2();//设置adddiv的 操作按钮
            var url = "<%=basePath%>t_contract/getT_contract?id=" + id + "&time=" + Math.random();
            $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
                setValue(data);
                //alert($("#effect_date").val()+""+jsonDateFormat($("#effect_date").val()));
                //$("#effect_date").val(jsonDateFormat($("#effect_date").val())); //重新设置日期类型的值
            });
            formReadOnly('ffAdd');//设置表单不可修改
        }

        //2、校验脚本初始化，start check
        $("#ffAdd").validate({
            submitHandler: function (form) {
                //alert($("#opType").val());
                if ($("#opType").val() == "add") {
                    add();
                } else if ($("#opType").val() == "edit") {
                    edit();
                }
            },
            rules: {
                contractid: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                contractno: {
                    //required: true,
                    maxlength: 256
                },
                conpanyid: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                conpanyname: {
                    //required: true,
                    maxlength: 45
                },
                buildingno: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                buildingname: {
                    //required: true,
                    maxlength: 45
                },
                houseid: {
                    //required: true,
                    digits: true,
                    //minlength: 1,
                    maxlength: 11
                },
                housename: {
                    //required: true,
                    maxlength: 1024
                },
                area: {
                    //required: true,
                    maxlength: 45
                },
                price: {
                    //required: true,
                    number: true,
                    //minlength: 1,
                    maxlength: 22
                },
                buildingtype: {
                    //required: true,
                    maxlength: 45
                },
                biztype: {
                    //required: true,
                    maxlength: 45
                },
                checkstatu: {
                    //required: true,
                    maxlength: 45
                },
                status: {
                    //required: true,
                    maxlength: 45
                },
                contracttype: {
                    //required: true,
                    maxlength: 45
                },
                linkman: {
                    //required: true,
                    maxlength: 45
                },
                info: {
                    //required: true,
                    maxlength: 45
                },
                companytel: {
                    //required: true,
                    maxlength: 45
                },
                signer: {
                    //required: true,
                    maxlength: 45
                },
                businesstype: {
                    //required: true,
                    maxlength: 45
                },
                attachpath: {
                    //required: true,
                    maxlength: 1024
                },
                totalprice: {
                    //required: true,
                    number: true,
                    //minlength: 1,
                    maxlength: 22
                },
                signtime: {
                    //required: true,
                    maxlength: 45
                },
                paytype: {
                    //required: true,
                    maxlength: 45
                },
                payday: {
                    //required: true,
                    maxlength: 45
                }
            }, //end rules;
            messages: {
                contractid: {
                    //required: " contractid不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> contractid最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                contractno: {
                    maxlength: "<font color='red'> contractno最大支持256位,输入的数据已经超过最大长度！</font>"
                },
                conpanyid: {
                    //required: " conpanyid不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> conpanyid最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                conpanyname: {
                    maxlength: "<font color='red'> conpanyname最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                buildingno: {
                    //required: " buildingno不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> buildingno最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                buildingname: {
                    maxlength: "<font color='red'> buildingname最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                houseid: {
                    //required: " houseid不能为空！",
                    digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'> houseid最大支持11位，输入的数据已经超过最大长度！</font>"
                },
                housename: {
                    maxlength: "<font color='red'> housename最大支持1,024位,输入的数据已经超过最大长度！</font>"
                },
                area: {
                    maxlength: "<font color='red'> area最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                price: {
                    //required: true,
                    number: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>单价最大支持22位,输入的数据已经超过最大长度！</font>"
                },
                buildingtype: {
                    maxlength: "<font color='red'> buildingtype最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                biztype: {
                    maxlength: "<font color='red'> biztype最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                checkstatu: {
                    maxlength: "<font color='red'> checkstatu最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                status: {
                    maxlength: "<font color='red'> status最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                contracttype: {
                    maxlength: "<font color='red'> contracttype最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                linkman: {
                    maxlength: "<font color='red'> linkman最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                info: {
                    maxlength: "<font color='red'> info最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                companytel: {
                    maxlength: "<font color='red'> companytel最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                signer: {
                    maxlength: "<font color='red'>签订人最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                businesstype: {
                    maxlength: "<font color='red'>行业最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                attachpath: {
                    maxlength: "<font color='red'> attachpath最大支持1,024位,输入的数据已经超过最大长度！</font>"
                },
                totalprice: {
                    //required: true,
                    number: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
                    //minlength: "<font color='red'>最少输入1位！</font>",
                    maxlength: "<font color='red'>总价最大支持22位,输入的数据已经超过最大长度！</font>"
                },
                signtime: {
                    maxlength: "<font color='red'> signtime最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                paytype: {
                    maxlength: "<font color='red'> paytype最大支持45位,输入的数据已经超过最大长度！</font>"
                },
                payday: {
                    maxlength: "<font color='red'>付款时间最大支持45位,输入的数据已经超过最大长度！</font>"
                }
            } //end message;
        }); //end validate;
    }) //end funciton read;
</script>
